﻿<phone:PhoneApplicationPage 
    x:Class="StopwatchApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:StopwatchApp"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
    DataContext="{Binding RelativeSource={RelativeSource Self}}">
    
    <phone:PhoneApplicationPage.Resources>
        <local:TimeSpanToDisplayStringConverter x:Key="TimeSpanToTextCoverterResource" />
        <local:LapDataListDesignPresentation x:Key="LapDataDesignPresentation" />
    </phone:PhoneApplicationPage.Resources>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent"
          d:DataContext="{StaticResource LapDataDesignPresentation}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0">
            <TextBlock x:Name="ApplicationTitle" Text="STOPWATCH" Style="{StaticResource PhoneTextNormalStyle}"/>
            <!--<TextBlock x:Name="PageTitle" Text="page name" Style="{StaticResource PhoneTextTitle1Style}"/>-->
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <StackPanel Grid.Row="0" Orientation="Vertical">
                <!--Lap Time-->
                <TextBlock Text="{Binding Path=CurrentLapDuration, Converter={StaticResource TimeSpanToTextCoverterResource}}"
                           HorizontalAlignment="Right"
                           Style="{StaticResource PhoneTextTitle2Style}" />
                <!--Overall time-->
                <TextBlock Text="{Binding Path=TotalStopWatchDuration, Converter={StaticResource TimeSpanToTextCoverterResource}}"
                            HorizontalAlignment="Right"
                            Style="{StaticResource PhoneTextTitle1Style}"/>

                <!--Buttons-->
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                    <Button Name="_StartStopButton" Width="150" Click="HandleStateChange"
                            Content="{Binding StartStopButtonText}" />
                    <Button Name="_LapResetButton" Width="150" Click="HandleStateChange"
                            Content="{Binding LapResetButtonText}"
                            IsEnabled="{Binding LapResetButtonEnabled}" />
                </StackPanel>
            </StackPanel>

            <!--Laps-->
            <ScrollViewer Grid.Row="1">
                <ItemsControl ItemsSource="{Binding AllLaps}">

                    <!--Define the appearance of the ItemsControl container.-->
                    <ItemsControl.Template>
                        <ControlTemplate TargetType="ItemsControl">
                            <Border BorderBrush="{StaticResource PhoneAccentBrush}"
                                    BorderThickness="1" CornerRadius="10">
                                <ItemsPresenter/>
                            </Border>
                        </ControlTemplate>
                    </ItemsControl.Template>
                    
                    <!--Define how the items will be contained.-->
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    
                    <!--Define what each item will look like.-->
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid ShowGridLines="False">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="150" />
                                    <ColumnDefinition Width="10" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>

                                <TextBlock Grid.Column="0" HorizontalAlignment="Left"
                                           Text="{Binding LapNumberAsString}"
                                           Style="{StaticResource PhoneTextTitle2Style}"
                                           Margin="12,0,0,0" />
                                <TextBlock Grid.Column="2" HorizontalAlignment="Left"
                                           Text="{Binding Path=LapDuration, Converter={StaticResource TimeSpanToTextCoverterResource}}"
                                           Style="{StaticResource PhoneTextTitle2Style}" />
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
        </Grid>
    </Grid>
 
    <!--Sample code showing usage of ApplicationBar-->
    <!--<phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Start" Click="StartButton_Click" />
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Lap" Click="LapButton_Click" />
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button3.png" Text="Stop" Click="StartButton_Click" />
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="Start" Click="StartButton_Click"/>
                <shell:ApplicationBarMenuItem Text="Lap" Click="LapButton_Click"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>-->

</phone:PhoneApplicationPage>